//
//  AUHud.swift
//  rrrr
//
//  Created by A on 2025/9/20.
//

import Foundation
import SVProgressHUD
class AUHud{
    private static let _setup: Void = {
        SVProgressHUD.setDefaultStyle(.dark)               // 样式：dark / light / custom
        SVProgressHUD.setDefaultMaskType(.clear)           // 背景遮罩：none / clear / black / gradient
        SVProgressHUD.setMinimumDismissTimeInterval(1.5)   // 最少显示时间
    }()
    
    private static func ensureSetup() {
        _setup
    }
    
    private static func configureForTextOnly() {
        SVProgressHUD.setDefaultMaskType(.none)
        SVProgressHUD.setImageViewSize(.zero)
    }
    
    /// 显示加载中
    static func show(_ status: String? = nil) {
        ensureSetup()
        if let status = status {
            SVProgressHUD.show(withStatus: status)
        } else {
            SVProgressHUD.show()
        }
    }
    
    /// 只显示文字提示（无图标） - 成功
    static func success(_ status: String? = "成功") {
        ensureSetup()
        configureForTextOnly()
        SVProgressHUD.show(withStatus: status)
        SVProgressHUD.dismiss(withDelay: 1.5)
    }

    /// 只显示文字提示（无图标） - 失败
    static func error(_ status: String? = "失败") {
        ensureSetup()
        configureForTextOnly()
        SVProgressHUD.show(withStatus: status)
        SVProgressHUD.dismiss(withDelay: 1.5)
    }

    /// 只显示文字提示（无图标）
    static func info(_ status: String) {
        ensureSetup()
        configureForTextOnly()
        SVProgressHUD.show(withStatus: status)
        SVProgressHUD.dismiss(withDelay: 1.5)
    }
    /// 纯文字提示（无图标）
    static func toast(_ status: String?) {
        ensureSetup()
        let message = status ?? ""
        configureForTextOnly()
        SVProgressHUD.showInfo(withStatus: message)
        SVProgressHUD.dismiss(withDelay: 1.5)
    }
    
    /// 隐藏 HUD
    static func dismiss() {
        ensureSetup()
        SVProgressHUD.dismiss()
    }
}
